<?php
App::import('Vendor','xtcpdf'); 
$tcpdf = new XTCPDF();
$textfont = 'helvetica'; // looks better, finer, and more condensed than 'dejavusans'
$tcpdf->setHeaderFont(array($textfont,'',40));

$tcpdf->SetAuthor("Ventura Rueda, Jose");
$tcpdf->SetAutoPageBreak(false);
$tcpdf->xheadercolor = array(150,0,0);
$tcpdf->xheadertext = 'Mi Empresa - Desarrollo ha medida';
$tcpdf->xheaderurl = 'http://mi_empresa.pe';
$tcpdf->xfootertext = 'Copyright Â© %d KBS Homes & Properties. All rights reserved.';

// add a page (required with recent versions of tcpdf)
$tcpdf->AddPage();


// cabeceras
$tcpdf->ln(8);
$tcpdf->SetFillColor(249, 249, 249);
$tcpdf->SetFont('helvetica', 'I', 10);
$tcpdf->MultiCell(190, 1, __('Datos Generales', TRUE), 'B', 'L', 1, 1, '', '', true);

$tcpdf->SetFont('helvetica', 'B', 7);
$tcpdf->MultiCell(20, 5,__('Fecha', TRUE), 0, 'L', 0, 0, '', '', true);
$tcpdf->MultiCell(4, 5, ':', 0, 'C', 0, 0, '', '', true);
$tcpdf->SetFont('helvetica', '', 7);
$tcpdf->MultiCell(96, 5, date('Y/m/d H:i:s'), 0, 'L', 0, 0, '', '', true);

$tableHeader = array(__('Nro', TRUE) ,__('Codigo', TRUE) , __('Articulo', TRUE), __('Unidades x Caja', TRUE), __('Unidad', TRUE),
					 __('Costo Soles', TRUE), __('Costo Dolares', TRUE));
					 
$tableHeaderW = array(10,20,70,20,20,25,25);//190
$tcpdf->mostrarHeaderTable($tableHeader,$tableHeaderW,15);	
$numeroLineasPagina = 51;
$numeroLineas = 0;
foreach($listaArticulos as $key=>$listaArticulo){
	$numeroLineas += 1;
	$nro = $key+1;
	
	if($numeroLineas == $numeroLineasPagina){
		$tcpdf->AddPage();
		$tcpdf->mostrarHeaderTable($tableHeader,$tableHeaderW);
		$numeroLineas = 0;
	}
	
	$tcpdf->Cell($tableHeaderW[0], 4, $nro, 1, 0, 'R', 1);		
	$tcpdf->Cell($tableHeaderW[1], 4, $listaArticulo['codigo'], 1, 0, 'R', 1);
	$tcpdf->Cell($tableHeaderW[2], 4, $listaArticulo['descripcion'], 1, 0, 'L', 1);
	$tcpdf->Cell($tableHeaderW[3], 4, $listaArticulo['unidadxcaja'], 1, 0, 'R', 1);
	$tcpdf->Cell($tableHeaderW[4], 4, $listaArticulo['unidad'], 1, 0, 'R', 1);
	$tcpdf->Cell($tableHeaderW[5], 4, number_format($listaArticulo['costo_soles'],2), 1, 0, 'R', 1);
	$tcpdf->Cell($tableHeaderW[6], 4, number_format($listaArticulo['costo_dolares'],2), 1, 0, 'R', 1); 
	$tcpdf->Ln();		
}
echo $tcpdf->Output('listaarticulos.pdf', 'I');
?>